<?php
class App_Module_Admin_Component_Structure_Tpl_Web extends App_Module_Admin_Tpl_Base
{
    public function CatList($cid, array $expandedElements = array())
    {
    	$this->cid = $cid;
		$this->expandedElements = $expandedElements;

        Mozg::SubAction()->Add('RequiredJS', array($this, 'CatListJS'), array(), 'CatList');

        $icons = array(
        	array(
        	'toggle' => array(
        					'title' => 'EXPAND/COLLAPSE',
        					'url' => '#'
        					),
        	)
        );

        return $this->LeftBlock('', $this->render('structure/_categories.phtml'), $icons);
    }

    public function SubCatList($cid, $rootId, array $expandedElements = array())
    {
    	$this->cid = $cid;
    	$this->rootId = $rootId;

    	$this->path = array_keys(Mozg_Mapper::Get('Structure')->GetList(array('pathId' => $this->cid)));
        $this->path[] = $this->cid;
        $this->path = array_merge($expandedElements, $this->path);

		return $this->render('structure/_innercategories.phtml');
    }

    public function CatListJS()
    {
    	return $this->render('structure/js/_categories.js');
    }

    protected function GetIconSet()
    {
    	$isAllowDelete = Mozg::User()->CheckAccess('admin', 'structure', 'del');

        $icons['edit'] = array(
        					'title' => 'EDIT',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=structure&action=add&cat={cat}&subcat={subcat}')
        					);

		$icons['html'] = array(
        					'title' => 'HTML',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=structure&action=editbody&cat={cat}&subcat={subcat}')
        					);

		if ($isAllowDelete || Mozg::User()->IsSuperUser())
		{
			$icons['delete'] = array(
	        					'title' => 'DELETE_CATEGORY?',
	        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=structure&action=del&cat={cat}&subcat={subcat}')
	        					);
		}
		else
		{
			$icons[] = array();
		}

		return $this->GetTpl('Icon')->GetIconSet($icons, 'categories');
    }
}